package com.pricecmp.service.impl;

import com.pricecmp.dao.DAOFacade;
import com.pricecmp.model.Staff;
import com.pricecmp.model.User;
import com.pricecmp.service.CommonService;

public class CommonServiceImpl implements CommonService {
	private DAOFacade dao;

	@Override
	public String login(String account, String password) {
		User u = null;
		if ((u = dao.findUser(account, password)) != null) {
			if (u.isNav()) {
				return "navy";
			} else {
				return "customer";
			}
		} else if (dao.findStaff(account, password) != null) {
			return "manager";
		} else {
			return "none";
		}
	}

	public DAOFacade getDao() {
		return dao;
	}

	public void setDao(DAOFacade dao) {
		this.dao = dao;
	}

	@Override
	public User getUserInfo(String userId, String password) {
		User user = dao.findUser(userId, password);
		return user;
	}

	@Override
	public Staff getStaffInfo(String jobNum, String password) {
		Staff staff = dao.findStaff(jobNum, password);
		return staff;
	}

	@Override
	public void register(String name, String password) {
		dao.addUser(name, password);
	}

}
